package fr.Orm.pierop.com;

import java.lang.reflect.Field;
import java.util.Map;

import org.apache.commons.beanutils.PropertyUtils;

import fr.myExceptions.pierop.com.beanIdNullException;
import fr.myExceptions.pierop.com.classNotFoundException;

class utilsFacade {

	public static String	isPersist(Object obj, Map<String, String> classMap) throws classNotFoundException
	{
		String table = classMap.get(obj.getClass().getName());
		if (table == null)
			throw new classNotFoundException(obj.getClass().getName() + " n'est pas une classe persistante.");
		return table;
	}
	
	public static Object	isString(Object obj, Field f) throws Exception
	{
		if (PropertyUtils.getSimpleProperty(obj, f.getName()).getClass().getName() == "java.lang.String")
			return "'" + PropertyUtils.getSimpleProperty(obj, f.getName()) + "'";
		return PropertyUtils.getSimpleProperty(obj, f.getName());
	}
	
	public static void	isNullId(Object obj, Field f, Map<String, String> m) throws Exception
	{
		try {
			if (PropertyUtils.getSimpleProperty(obj, f.getName()) == null && m.get(f.getName()).equals("ID"))
				throw new beanIdNullException();
		}
		catch (java.lang.NoSuchMethodException e) {  }
	}
	
}
